﻿
<%@ Page language="c#" Inherits="Mysoft.Crm.Application.Pages.Tools.FormEditor.Dialogs.Section" CodeBehind="Mysoft.Crm.Application.Pages.Tools.dll" %>
<%@ Register TagPrefix="cnt" Namespace="Mysoft.Crm.Application.Controls" Assembly="Mysoft.Crm.Application.Components" %>
<html>
<head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312"/>
<title><%= title %></title>
<link rel="stylesheet" type="text/css" href="/_common/styles/global.css">
<link rel="stylesheet" type="text/css" href="/_common/styles/select.css">
<link rel="stylesheet" type="text/css" href="/_nav/tabs.css">
<link rel="stylesheet" type="text/css" href="/Tools/FormEditor/Styles/dialogs.css">
<script language="javascript" src="/_controls/settings.aspx"></script>
<script language="javascript" src="/_common/scripts/global.js"></script>
<script language="javascript" src="/Tools/FormEditor/Scripts/objects.js"></script>
<script language="javascript" src="/Tools/FormEditor/Scripts/dialogs.js"></script>
<script language="javascript">

	var _oFormXml;
	
	
	function window.onload()
	{
		_oFormXml = window.dialogArguments.FormXml;

		var oSection = window.dialogArguments.Section;

		crmDialog.SectionName.value			= oSection.SectionName;
		crmDialog.SectionName.defaultValue	= oSection.SectionName;
		
		var oTabs = _oFormXml.selectNodes("/entity/form/tabs/tab")
		
		var sTabsHtml = "<span class='selectBox' value='" + oSection.TabName + "' name='TabName'><table cellspacing='0' cellpadding='2' style='display: none;'>";

		var i;
		var iLen = oTabs.length;
		
		for (i = 0; i < iLen; i++)
		{
			sTabsHtml += "<tr><td val='" + oTabs[i].getAttribute("name") + "'>" + oTabs[i].firstChild.firstChild.getAttribute("description") + "</td></tr>";
		}
		
		sTabsHtml += "</table></span>";
		
		Tabs.innerHTML = sTabsHtml;

		crmDialog.ShowLabel.checked	= oSection.ShowLabel;
		crmDialog.ShowBar.checked	= oSection.ShowBar;

		var oLabels	= oSection.Labels;

		if (oLabels)
		{
			crmDialog.Description.value			= oLabels[0].Description;
			crmDialog.Description.defaultValue	= oLabels[0].Description;
		}
		
		SetShowBarState();
		
		crmDialog.Description.focus();
	}


	function Ok()
	{
		crmDialog.Description.value = Trim(crmDialog.Description.value);
		
		var sSectionDesc = crmDialog.Description.value;
		
		crmDialog.SectionName.value = sSectionDesc.toLowerCase();
		
		if (sSectionDesc.length == 0)
		{
			alert( "Enter a section name." );

			crmDialog.Description.select();

			return;
		}
		
		if (sSectionDesc.indexOf('"') > -1 || sSectionDesc.indexOf("'") > -1 || sSectionDesc.indexOf("\\") > -1 || sSectionDesc.indexOf("&") > -1 || sSectionDesc.indexOf('|') > -1 || sSectionDesc.indexOf('<') > -1)
		{
			//alert( "Section names cannot contain any of the following characters:" + " \" ' \\ & | <");
			alert("区域名称不能包含下列字符：" + " \" ' \\ & | <");

			crmDialog.Description.select();

			return;
		}
		
		if (crmDialog.SectionName.value != crmDialog.SectionName.defaultValue)
		{
			if (_oFormXml.selectSingleNode("/entity/form/tabs/tab/sections/section[@name = '" + crmDialog.SectionName.value + "']"))
			{
				//alert( "The section name you entered is already in use." );
				alert("您键入的区域名称已经被使用了。");
				crmDialog.Description.select();

				return;
			}
		}
	
		window.returnValue	= new SectionObj(
								crmDialog.TabName.returnValue,
								crmDialog.SectionName.value,
								crmDialog.ShowLabel.checked,
								crmDialog.ShowBar.checked,
								new Array(new LocalizedObj(crmDialog.Description.value, ORG_LANGUAGE_CODE))
							);
		
		window.close();
	}
	
	
	function SetShowBarState()
	{
		if (crmDialog.ShowLabel.checked)
		{
			with (crmDialog.ShowBar)
			{
				disabled		= false;
				style.cursor	= "hand";
			}
			
			with (ShowBarLabel)
			{
				disabled		= false;
				style.cursor	= "hand";
			}
		}
		else
		{
			with (crmDialog.ShowBar)
			{
				checked			= false;
				disabled		= true;
				style.cursor	= "default";
			}
			
			with (ShowBarLabel)
			{
				disabled		= true;
				style.cursor	= "default";
			}
		}
	}

</script>
</head>
<body>
	<form name="crmDialog">
		<input type="hidden" name="SectionName">
		<table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%">
			<tr>
				<td class="header">
					<div class="header"><%= title %></div>
					<div class="headerdesc"><%= description %></div>
				</td>
			</tr>
			<tr>
				<td class="main">
					<table width="100%" height="100%" cellspacing="0" cellpadding="0">
						<tr height="25">
							<td>
								<cnt:AppTabBar id="crmTabBar" runat="server"/>
							</td>
						</tr>
						<tr>
							<td>
								<div id="tab0" class="tab" style="display: inline;">
									<fieldset>
										<legend><!-Name->名称&nbsp;</legend>
										<div class="desc">
											<!-Specify a unique name.->
											指定一个唯一名称
										</div>
										<table cellpadding="0" cellspacing="5" width="100%" style="table-layout: fixed;">
											<col width="50"><col>
											<tr>
												<td class="req"><!-Name->名称</td>
												<td><input name="Description" type="text" maxlength="100"></td>
											</tr>
										</table>
									</fieldset>
									<br>
									<fieldset>
										<legend><!-Label->标识&nbsp;</legend>
										<div class="desc">
											<!-Specify whether to show this section's properties on the form.->
											指定是否在表单上显示区域属性。
										</div>
										<table cellpadding="0" cellspacing="5" width="100%" style="table-layout: fixed;">
											<col width="15"><col width="15"><col>
											<tr>
												<td><input id="ShowLabel" name="ShowLabel" type="checkbox" class="checkbox" onclick="SetShowBarState();"></td>
												<td colspan="2"><label for="ShowLabel"><!-Show the name of this section on the form->在表单上显示区域名称</label></td>
											</tr>
											<tr>
												<td></td>
												<td><input id="ShowBar" name="ShowBar" type="checkbox" class="checkbox"></td>
												<td><label id="ShowBarLabel" for="ShowBar"><!-Show divider line below the section name->在区域名称下面显示分割线</label></td>
											</tr>
										</table>
									</fieldset>
									<br>
									<fieldset>
										<legend><!-Location->提示&nbsp;</legend>
										<div class="desc">
											<!-Select the tab you want this section to appear under.->选择本区域所在的标签
										</div>
										<table cellpadding="0" cellspacing="5" width="100%">
											<tr>
												<td id="Tabs"></td>
											</tr>
										</table>
									</fieldset>
								</div>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td class="buttons">
					<button id="btnDialogOk" onclick="Ok();">确定</button>
					&nbsp;
					<button id="btnDialogCancel" onclick="Cancel();">取消</button>
				</td>
			</tr>
		</table>
	</form>
</body>
</html>